package com.tanhua.admin.module.dynamicmanage.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.admin.module.dynamicmanage.service.VideoInfoService;
import com.tanhua.common.mapper.VideoInfoMapper;
import com.tanhua.common.pojo.VideoInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class VideoInfoServiceImpl implements VideoInfoService {

    @Autowired
    private VideoInfoMapper videoInfoMapper;

    @Override
    public Map<String, Object> queryVideoInfoList(Integer pagesize, Integer page, String sortProp, String sortOrder, Long uid) {
        //查询视频信息表
        QueryWrapper<VideoInfo> queryWrapperVI = new QueryWrapper<>();

        if (sortOrder.equals("ascending")){
            queryWrapperVI.orderByAsc(StrUtil.toUnderlineCase(sortProp));
        }else if (sortOrder.equals("descending")){
            queryWrapperVI.orderByAsc(StrUtil.toUnderlineCase(sortProp));
        }

        if (ObjectUtil.isNotEmpty(uid)){
            queryWrapperVI.eq("user_id",uid);
        }

        //得到分页对象
        IPage<VideoInfo> videoInfoIPage = videoInfoMapper.selectPage(new Page<>(page, pagesize), queryWrapperVI);

        HashMap<String,Object> map = new HashMap<>();
        map.put("videoInfoPage",videoInfoIPage);
        Integer count = videoInfoMapper.selectCount(queryWrapperVI);
        map.put("count",count);
        return map;
    }
}
